﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Olitee.WorkScheduler.Interfaces;
using System.Threading.Tasks;

namespace Olitee.WorkScheduler.Tests.Model
{
    public class TestWorkProcessor : Interfaces.IWorkProcessor
    {
        public Task<IWorkItem> Start(IWorkItem workItem)
        {
            var item = workItem as TestWorkItem;

            TaskCompletionSource<IWorkItem> tcs = new TaskCompletionSource<IWorkItem>();

            item.TimeStarted = DateTime.Now;
            item.Progress = -1;

            // Simulate a processing delay
            Thread.Sleep(item.SimulatedProcessingDelay);

            item.Status = Enumerations.WorkItemStatus.Complete;
            item.TimeCompleted = DateTime.Now;
            tcs.SetResult(workItem);

            return tcs.Task;
        }

    }
}
